<!-- @formatter:off -->
<!-- <route lang="json5" type="home">
{
  style: {
    backgroundColor: '#ffffff',
  },
}
</route> -->
<!-- @formatter:on -->

<script setup lang="ts">
import useLogin from '@/hooks/useLogin'
import { OptionsCallback } from '@/models/login'
import { HOME_PAGE, LOGIN_PAGE } from '@/models/sys'

onLoad(async (options) => {
  if (options?.corp_id) {
    uni.showLoading({ title: '请稍等' })
    callback.setCorpId(options?.corp_id)
    await callback.getCode()
    await callback.getLogin()

    callback.checkLoginResult()
    callback.openTimer()
  }
})

onUnmounted(() => {
  callback.closeTimer()
})

const optionsCallback: OptionsCallback = {
  successLogin() {
    uni.showToast({ title: '登录成功' })

    setTimeout(() => {
      uni.reLaunch({
        url: HOME_PAGE,
      })
    }, 500)
  },
  needQrcode() {
    uni.reLaunch({
      url: LOGIN_PAGE,
    })
  },
  scanQrcode(status) {
    // if(status.)
  },
}

const { qrcode, checkLoginData, ...callback } = useLogin(optionsCallback)
</script>

<template>
  <view></view>
</template>

<style lang="scss" scoped></style>
